import request, { scope } from '../../utils/request';

const addressUrl = scope('user/address');

/**
 * 添加地址信息
 * @param {*} address
 * @returns
 */
export const addAddress = (address) => {
  /**
   * {
   *   "userId": "1", // 必填项
   *   "mobile": "15037257831", // 必填项
   *   "isDefault": "1", // 必填项
   *   "consignee": "胡欣哲", // 必填项
   *   "postCode": "454350", // 非必填项
   *   "address": "原阳大哥大 大得很" // 必填项
   * }
   */
  return request({
    url: addressUrl('save'),
    method: 'post',
    data: { ...address },
  });
};

/**
 * 查地址 by userId
 * @param {*} userId
 * @param {*} page
 * @param {*} size
 * @returns
 */
export const findAddress = (userId, page = 1, size = 10) => {
  return request({
    url: addressUrl(`find/${page}/${size}`),
    method: 'post',
    data: { userId },
  });
};

export const findAddressById = (id) => {
  return request({
    url: addressUrl(`find/${id}`),
    method: 'get'
  });
};

export const updateAddress = (address) => {
  return request({
    url: addressUrl('update'),
    method: 'post',
    data: address
  });
};

export const deleteAddress = (id) => {
  return request({
    url: addressUrl(`del/${id}`),
    method: 'post'
  });
};
